package ca.cbc.msb.mediacms;

import java.util.List;

import javax.jms.JMSException;
import javax.naming.NamingException;

import ca.cbc.msb.entity.MSBMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ca.cbc.msb.entity.MSBNotification;
import ca.cbc.msb.enums.QueueEnum;
import ca.cbc.msb.mq.MessageUtil;
import ca.cbc.msb.mq.MessageUtilImpl;
import ca.cbc.msb.util.AppConfig;

public class DeletedReleaseNotificationHandler implements NotificationHandler {
	private static Logger logger = LoggerFactory.getLogger(DeletedReleaseNotificationHandler.class);

	private static final String filterParam = "filter=Release|delete";


	private String sequenceFile = AppConfig.getProperty("nh.deletedrelease.sequenceid.filename");


    private MessageUtil messageUtil;
	public DeletedReleaseNotificationHandler()
	{
        try {
                   messageUtil = new MessageUtilImpl();
               } catch (NamingException e) {
                   logger.error("Error in creating message util", e);
                   throw new RuntimeException(e);
               } catch (JMSException e) {
                   logger.error("Error in creating message util", e);
                   throw new RuntimeException(e);
               }


	}
	
	@Override
	public void handleMessage(List<MSBNotification> nList) throws NamingException, JMSException
	{       
        logger.debug("-----Pushing to DeleteNotificationQueue-----");
        for(MSBNotification n : nList)
        {
            MSBMessage message = new MSBMessage();
            message.setNotification(n);
        	messageUtil.submitMessage(QueueEnum.DeleteNotificationQueue, message);
            messageUtil.commit();
        }
	}
	
	@Override
	public String getFilterParam() {
		return filterParam;
	}

    @Override
    public String getSequenceFileName() {
        return sequenceFile;
    }

    @Override
    public void cleanUp() {
        logger.info("closing the jms session for Delete Release Notification Handler");
        messageUtil.disconnect();
    }
}


